
/**
 * @file app.js
 * @author maoquan(maoquan@htsc.com)
 */
import 'babel-polyfill';
import dva from 'dva';
import { hashHistory,browserHistory } from 'dva/router';
import createLoading from 'dva-loading';
import createLogger from 'redux-logger';
import { persistStore, autoRehydrate } from 'redux-persist';
import { message,notification } from 'antd';

import createSensorsLogger from './middlewares/sensorsLogger';
import createActivityIndicator from './middlewares/createActivityIndicator';
import routerConfig from './router';
import persistConfig from './config/persist';
import { isExpressionWithTypeArguments } from 'typescript';


var _paq = _paq || [];
_paq.push(["setDomains", ["*.www.zxw.com"]]);
// _paq.push(['setCustomVariable','1','id',id_val,'page']);//xxx_val为变量，请根据需求修改
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function(){
var u="http://168.61.2.107:8081/webproducer/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 10]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
console.log(333,_paq);
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();



console.log(333,_paq);
const ERROR_MSG_DURATION = 5; // 3 秒

const extraEnhancers = [];
if (persistConfig.active) {
	extraEnhancers.push(autoRehydrate());
}


//按照有效数字位数进行四舍五入，默认6位有效数字
Math.signFigures = function(num, rank = 6) {
    if(!num) return(0);
    const sign = num / Math.abs(num);
    const number = num * sign;
    const temp = rank - 1 - Math.floor(Math.log10(number));
    let ans;
    if (temp > 0) {
        ans = parseFloat(number.toFixed(temp));
    } else if (temp < 0) {
        const temp = Math.pow(10, temp);
        ans = Math.round(number / temp) * temp;
    } else {
        ans = Math.round(number);
    }
    return (ans * sign);
};

// 数字转换成百分比保留2位小数
Number.prototype.toPercent = function(){
	return (Math.round(this * 10000)/100).toFixed(2) + '%';
	}
Number.prototype.multiplyBy100 = function(){
		return (Math.round(this * 10000)/100).toFixed(2);
		}


// 错误处理
const onError = (e) => {
	const { message: msg  } = e;
	console.log('e>>>>',e,msg)
	if (msg === 'Access Denied' || msg === 'Access is denied') {
		// message.error('登录超时，请重新登录！');
		if (!location.href.indexOf('login') > -1) {
			const urlHash = location.hash;
			let from = urlHash.slice(1, urlHash.indexOf('?'));
			if (from.indexOf('login') > -1) {
				from = '/';
			}
			window.location.href = `${location.href.split('#')[0]}#/login`;
		}
	} else {
		// message.error(msg, ERROR_MSG_DURATION);
		notification['error']({
		 message:msg,
		 style: {
			 width:500,
    height:100,
    marginLeft: 400 - 600,
  	},
		});
	}
};

// 1. Initialize
let NODE_ENV
// const NODE_ENV='development'
// const NODE_ENV='production'
// console.log(`process.env.NODE_ENV`,process.env.NODE_ENV,`NODE_ENV`,NODE_ENV);


let app
// if((NODE_ENV||process.env.NODE_ENV)==='development'){
	app = dva({
		history: hashHistory,
		onAction: [createLogger(), createSensorsLogger()],
		extraEnhancers,
		onError,
	});
// }else{
	// app = dva({
	// 	history: hashHistory,
	// 	extraEnhancers,
	// 	onError,
	// });
// }


// 2. Plugins
app.use(createLoading({ effects: true }));
app.use(createActivityIndicator());

// 3. Model
app.model(require('./models/login'));
app.model(require('./models/app'));
app.model(require('./models/allProduct'));
// app.model(require('./models/insrealtime'));
app.model(require('./models/trade'));
app.model(require('./models/holding'));
app.model(require('./models/instprofit'));
app.model(require('./models/combiprofit'));
app.model(require('./models/pdtdashboard'));
app.model(require('./models/prolist'));
app.model(require('./models/income'));
app.model(require('./models/kpi'));
app.model(require('./models/overview'));
app.model(require('./models/dailysummary'));
app.model(require('./models/dailysummaryTarget'));
app.model(require('./models/dailysummaryStrategy'));
app.model(require('./models/realtime'));
app.model(require('./models/realtimeTarget'));
app.model(require('./models/realtimeStrategy'));
app.model(require('./models/featureList'));
app.model(require('./models/closedPositions'));
app.model(require('./models/accountAssets'));
app.model(require('./models/marketData'));
app.model(require('./models/brinson'));
app.model(require('./models/brinsonResult'));
app.model(require('./models/custodianEvaluation'));
app.model(require('./models/fundResult'));
app.model(require('./models/accountUser'));
app.model(require('./models/accoutUserPer'));
app.model(require('./models/retailFeatureList'));
app.model(require('./models/retailClosedPositions'));
app.model(require('./models/retailAccountAssets'));
app.model(require('./models/pdtmanagement'));
app.model(require('./models/pdtEdit'));
app.model(require('./models/pdtPosition'));
app.model(require('./models/pdtTrade'));
app.model(require('./models/pdtFunds'));
app.model(require('./models/varAnalysis'));
app.model(require('./models/replayList'));
app.model(require('./models/replayDetail'));
app.model(require('./models/infoRevise'));
app.model(require('./models/passwordRevise'));
app.model(require('./models/fundPool'));
app.model(require('./models/myAttention'));
app.model(require('./models/scheduling'));
app.model(require('./models/schedulingDetails'));
app.model(require('./models/retail'));
app.model(require('./models/standard'));
app.model(require('./models/performance'));
app.model(require('./models/configSchemeStructure'));
app.model(require('./models/ConfigSimulation'));
app.model(require('./models/role'));
app.model(require('./models/menu'));
app.model(require('./models/periodReplay'));
app.model(require('./models/privateManager'));
app.model(require('./models/privatePdt'));
app.model(require('./models/privateGame'));
app.model(require('./models/dailyReplay'));
app.model(require('./models/portfolioPerformance'));
app.model(require('./models/holdingAnalysis'));
app.model(require('./models/performanceAttribution'));
app.model(require('./models/portfolio'));
app.model(require('./models/retailEducationDetail'));
app.model(require('./models/combinatorialAnalysis'));
app.model(require('./models/benchmarkMgt'));
app.model(require('./models/researchReport'));





// 4. Router
app.router(routerConfig);

// 5. Start
app.start('#app');

// 6. redux-persist
if (persistConfig.active) {
	persistStore(app._store, persistConfig); // eslint-disable-line
}
